#include "StdAfx.h"

#include "SFML/Audio/SoundBuffer.hpp"
#include "../Vocoder/Vocoder.h"
#include "../Vocoder/PerformanceMonitor.h"
#include "Modulator.h"

ModulatorX::ModulatorX(PerformanceMonitor* performance)
{
	this->performance = performance;
}

ModulatorX::~ModulatorX(void)
{
}

int ModulatorX::GetSampleLength(const std::string& filename)
{
	sf::SoundBuffer soundFile;
	soundFile.LoadFromFile(filename);
	return soundFile.GetSamplesCount();
}

void ModulatorX::Vocode(Vocoder* vocoder, const std::string& filename, int windowLength)
{
	sf::SoundBuffer soundFile;
	soundFile.LoadFromFile(filename);
	int fileLen = soundFile.GetSamplesCount();
	short* sample = (short*)soundFile.GetSamples();
	std::vector<short> sampleBuf(windowLength);
	for(int i=0; i<fileLen-windowLength; i+=windowLength)
	{
		for(int j=0; j<windowLength; j++)
		{
			sampleBuf[j] = sample[i+j];
		}
		performance->ReceivedModulator(windowLength);
		vocoder->CreateCarrierSampleAndVocode(&sampleBuf[0], windowLength);		
	}	
}